package com.duobaoyu.dby.supply.admin.controller.config;

import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceChannelSettingConfigAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.ChannelSetConfigDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.ChannelSettingConfigVO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.ChannelSettingDetailConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 渠道设置配置
 * @author liyang
 * @version 1.0.0
 * @ClassName ChannelSettingConfigController
 * @Description 渠道设置配置
 * @createTime 13:10:00 2023/08/25
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/setting-config")
@Api(value = "channel-setting-config-controller", tags = "渠道设置配置")
public class ChannelSettingConfigController {

    private final ResourceChannelSettingConfigAdminClient resourceChannelSettingConfigAdminClient;

    /**
     * 渠道配置列表
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "渠道配置列表", notes = "渠道配置列表")
    @SupplySysLog(value = "渠道配置列表",operationType = OperationTypeEnum.SELECT)
    public R<List<ChannelSettingConfigVO>> channelSettingConfigList(){

        return R.ok(resourceChannelSettingConfigAdminClient.channelSettingConfigList());
    }

    /**
     * 渠道配置置顶
     * @param channelCode
     * @return
     */
    @GetMapping("/topping/{channelCode}")
    @ApiOperation(value = "渠道配置置顶", notes = "渠道配置置顶")
    @SupplySysLog(value = "渠道配置置顶",operationType = OperationTypeEnum.UPDATE)
    public R<Boolean> configTopping(@NotBlank(message = "渠道编码不能为空") @PathVariable("channelCode") String channelCode) {

        return R.ok(resourceChannelSettingConfigAdminClient.configTopping(channelCode));
    }

    /**
     * 根据配置Id获取配置参数详情
     * @return
     */
    @GetMapping("/detail/{configId}")
    @ApiOperation(value = "根据配置Id获取配置参数详情", notes = "根据配置Id获取配置参数详情")
    @SupplySysLog(value = "根据配置Id获取配置参数详情",operationType = OperationTypeEnum.SELECT)
    public R<ChannelSettingDetailConfigVO> configDetail(@NotNull(message = "配置ID不能为空") @PathVariable("configId") Long configId) {

        return R.ok(resourceChannelSettingConfigAdminClient.configDetailById(configId));
    }

    /**
     * 根据配置Id修改配置参数
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "根据配置Id修改配置参数", notes = "根据配置Id修改配置参数")
    @SupplySysLog(value = "根据配置Id修改配置参数",operationType = OperationTypeEnum.UPDATE)
    public R<Boolean> updateConfig(@Validated @RequestBody ChannelSetConfigDTO channelSettingConfig) {

        return R.ok(resourceChannelSettingConfigAdminClient.updateConfig(channelSettingConfig));
    }
}
